package com.ymatou.productstock.api.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.productstock.api.parameter.CatalogBean;
import com.ymatou.productstock.api.service.AuditProductActivityStockCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.data.Data201805;
import com.ymttest.business.service.ActivityCallService;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.NewJavaMongoCheckService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductPriceCallService;
import com.ymttest.business.service.ProductStockCallService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.YmtProductActivityStock;
import com.ymttest.database.model.YmtProductsInActivity;
import com.ymttest.database.mongo.ProductActivityStockInfoWapper;
import com.ymttest.database.mongo.ProductDetailModelWapper;
import com.ymttest.database.mongo.ProductListingModelWapper;
import com.ymttest.database.mongo.ProductStockInfoWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.mongo.jproduct.ProductTimeStampBean;
import com.ymttest.database.mongo.jproduct.ProductTimeStampWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.database.sqlwapper.YmtProductsInActivityWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;

public class Ts_AuditProductActivityStock {
	//base data
	private static String sellerName = EnvSetup.getData("productsellername");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static int activityStartId = Integer.parseInt(EnvSetup.getData("productActivityStartId"));
	//sql db
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static YmtProductActivityStockWapper ymtProductActivityStockWapper = new YmtProductActivityStockWapper();
	//mongo db
	private static ProductStockInfoWapper productStockInfoWapper=new ProductStockInfoWapper();
	private static ProductActivityStockInfoWapper productActivityStockInfoWapper= new ProductActivityStockInfoWapper();
	private static ProductTimeStampWapper productTimeStampWapper = new ProductTimeStampWapper();
	
	
	private static ProductListingModelWapper productListingModelWapper = new ProductListingModelWapper();
	private static ProductDetailModelWapper productDetailModelWapper = new ProductDetailModelWapper();
	
	//API
	private static AuditProductActivityStockCall activityStockCall = new AuditProductActivityStockCall();
	
	
	private static String dateformat = "HHmmssSSS";
	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("初始化活动库存");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(activityStockCall.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end();
	}

	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AuditProductActivityStock_001() {
		Logger.start(true, "初始化活动库存,原商品单规格，全部报名");
		try{
			//String productId = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null).getJSONObject("Data").getString("ProductID");
//			String productId = ProductPriceCallService.getProdPriceWit.hActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
//			String productId = ProductManagerCallServiceV2.getStgProductId(sellerName, sellerId, 999999);
			List<Map> mpids = ProductManagerCallServiceV2.createProducts(sellerId, sellerName, 1);
			String productId=mpids.get(0).get("productId").toString();
			ProductManagerCallServiceV2.addActivity(mpids);
			//Thread.sleep(3000);
			Logger.comment("productId:"+productId);
			//时间戳检查
			YMTDateUtil.waitTime(10);
			ProductTimeStampBean productTimeStampBean = new ProductTimeStampBean();
			productTimeStampBean.setProductId(productId); 
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				Map<String, Object> ret = productTimeStampWapper.getByProductId(productId);
				productTimeStampBean.setSut((Date)ret.get("sut"));
				productTimeStampBean.setCut((Date)ret.get("cut"));
				//Logger.verifyIsNull(ret.get("aut"),"ProductTimeStamp aut 应该没有"); 
			}		
             //此站点sellerservice.evt.ymatou.com 不存在
			//ActivityCallService.applyProductInActivity(sellerId, productId, String.valueOf(activityStartId), new HashMap<String,Object>());
			
			YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalogsI.getsCatalogId();
			int catalogNum = ymtCatalogsI.getiNum();
			String sku = ymtCatalogsI.getsSKU();
			
			
			int productActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			Logger.debug("ProductInActivityId: "+ productActivityId);
			
			int activityNum = 10;
//			int activityNum=Integer.parseInt(ymtProductActivityStock.get("iStockNum").toString());
//			Logger.comment("activityNum:"+activityNum);
			//新增 
			YmtProductsInActivity productInActivity=new YmtProductsInActivityWapper().selectByProductId(productId);
			activityStartId=productInActivity.getIactivityid();
			
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("UserID", sellerId);
			updateMap.put("ActivityID", activityStartId);
			updateMap.put("ProductId", productId);
			updateMap.put("ProductActivityId", productActivityId);
			updateMap.put("IsFbxProduct", false);
			updateMap.put("FBXCatalogLockList[0]->CatalogId", catalogId);
			updateMap.put("FBXCatalogLockList[0]->Stock", activityNum);
			updateMap.put("FBXCatalogLockList[0]->Sku", sku);
			
			JSONObject retBean = activityStockCall.callAndGetReturnData(updateMap);
			
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			Logger.verifyEquals(1, retBean.getJSONObject("Data").getJSONObject("XLoboResult").getJSONArray("BatchLockResults").getJSONObject(0).getInt("Status"), "响应报文-返回码Status");
			
			//check sql
			//SQL-Ymt_Catalogs
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum-activityNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock 商品库存数量
			Map ymtProductActivityStock= ymtProductActivityStockWapper.selectBy(MapUtil.hashMap("sproductid",productId,"scatalogid",catalogId));

			Map<String, Object> tgtsqlMap = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId, //商品规格Id
															"istocknum",activityNum,//库存数量
															"iactivityid",activityStartId); //活动Id
//															"iactivityid",activityStartId); //活动Id
			
//			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductActivityStock),"SQL-Ymt_ProductActivityStock 商品库存数量");
			AssertService.assertResultEqual(tgtsqlMap, ymtProductActivityStock,"SQL-Ymt_ProductActivityStock 商品库存数量");
			
			//check mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				Logger.comment("oldmongoCheck");
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum-activityNum),productStockInfoWapper.getByCatalogId(catalogId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = productActivityStockInfoWapper.getByProductId(productId);
				Map<String, Object> tgtOldMongoMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId, //商品规格Id
																		"ActivityStockNum",(activityNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongoMap, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				Logger.comment("newmongoCheck");
				//ProductDetailModel
				JSONArray CatalogList = new JSONArray(productDetailModelWapper.getProductId(productId).get("CatalogList").toString());
				Logger.verifyEquals(catalogId, CatalogList.getJSONObject(0).getString("CatalogId"), "ProductDetailModel - CatalogId");
				
				JSONArray StockList = CatalogList.getJSONObject(0).getJSONArray("StockList");
				Logger.verifyEquals(2, StockList.length(), "ProductDetailModel - StockList 个数检查");
				//共享库存
				JSONObject baseStock ;
				//活动库存
				JSONObject activityStock;
				
				if (StockList.getJSONObject(0).getInt("StockType") ==0){
					baseStock = StockList.getJSONObject(0);
					activityStock = StockList.getJSONObject(1);
				}else{
					baseStock = StockList.getJSONObject(1);
					activityStock = StockList.getJSONObject(0);
				}
				
				
				AssertService.assertResultEqual(MapUtil.hashMap("StockType", 0, "Stock", (catalogNum-activityNum)), MapUtil.jsonToMap(baseStock), 
																			"ProductDetailModel - StockList 共享库存");
				AssertService.assertResultEqual(MapUtil.hashMap("StockType", 1, "Stock", activityNum,"ProductInActivityId",productActivityId), 
													MapUtil.jsonToMap(activityStock), "ProductDetailModel - StockList 活动库存");
				
				//ProductListingModel
				
				Map<String, Object> productListingModelMap = productListingModelWapper.getProductId(productId);
				Logger.verifyEquals((catalogNum-activityNum), Integer.parseInt(productListingModelMap.get("CatalogStock").toString()), "Mongo-ProductListingModel CatalogStock");
				
				JSONObject ActivityStockBean = new JSONArray(productListingModelMap.get("ActivityStockList").toString()).getJSONObject(0);
				Logger.verifyEquals(productActivityId, ActivityStockBean.getInt("ProductInActivityId"), "Mongo-ProductListingModel ProductInActivityId");
				Logger.verifyEquals(activityNum, ActivityStockBean.getInt("ActivityStock"), "Mongo-ProductListingModel ActivityStock");

			}
			//new ProductManagerCallServiceV2().offSaleAllProduct(sellerId);
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productActivityId);
				
				Map<String, Object> ret = productTimeStampWapper.getByProductId(productId);
				Logger.verifyEquals(false,productTimeStampBean.getCut().equals((Date)ret.get("cut")),"ProductTimeStamp cut应该变化");
				Logger.verifyEquals(true,productTimeStampBean.getSut().equals((Date)ret.get("sut")),"ProductTimeStamp sut应该没有变化");
				//Logger.verifyNotNull(ret.get("aut"),"ProductTimeStamp aut 应该有");
			}
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_AuditProductActivityStock_002() {
		Logger.start(true, "初始化活动库存,原商品多规格");
		try{
			//发布商品 多规格
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc1.json");
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",sellerId,"LoginID",sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			//此站点sellerservice.evt.ymatou.com 不存在
//			ActivityCallService.applyProductInActivity(sellerId, productId, String.valueOf(activityStartId), new HashMap<String,Object>());
			
			int productActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			Logger.debug("ProductInActivityId: "+ productActivityId);
			Thread.sleep(3000);
			
			YmtCatalogsI ymtCatalogsI1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId1 = ymtCatalogsI1.getsCatalogId();
			int catalogNum1 = ymtCatalogsI1.getiNum();
			String sku1 = ymtCatalogsI1.getsSKU();
			
			int activityNum1 = 10;
			
			
			YmtCatalogsI ymtCatalogsI2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1);
			String catalogId2 = ymtCatalogsI2.getsCatalogId();
			int catalogNum2 = ymtCatalogsI2.getiNum();
			String sku2 = ymtCatalogsI2.getsSKU();
			int activityNum2 = 11;
			
			//规格1 初始化库存
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("UserID", sellerId);
			updateMap.put("ActivityID", activityStartId);
			updateMap.put("ProductId", productId);
			updateMap.put("ProductActivityId", productActivityId);
			updateMap.put("IsFbxProduct", false);
			updateMap.put("FBXCatalogLockList[0]->CatalogId", catalogId1);
			updateMap.put("FBXCatalogLockList[0]->Stock", activityNum1);
			updateMap.put("FBXCatalogLockList[0]->Sku", sku1);
			updateMap.put("FBXCatalogLockList[1]->CatalogId", catalogId2);
			updateMap.put("FBXCatalogLockList[1]->Stock", activityNum2);
			updateMap.put("FBXCatalogLockList[1]->Sku", sku2);
			
			JSONObject retBean1 = activityStockCall.callAndGetReturnData("auditproductactivitystockcalltpl_001.json",updateMap);
			
			Logger.verifyEquals(200, retBean1.getInt("Code"), "响应报文-返回码");
			Logger.verifyEquals(1, retBean1.getJSONObject("Data").getJSONObject("XLoboResult").getJSONArray("BatchLockResults").getJSONObject(0).getInt("Status"), "响应报文-返回码Status");
			
		

			//check sql
			//SQL-Ymt_Catalogs
			YmtCatalogsI ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId1);
			Logger.verifyEquals((catalogNum1-activityNum1), ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			YmtCatalogsI ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId2);
			Logger.verifyEquals((catalogNum2-activityNum2), ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			
			//SQL-Ymt_ProductActivityStock 商品库存数量
			YmtProductActivityStock ymtProductActivityStock1=ymtProductActivityStockWapper.selectByCatalogId(catalogId1);
			Map<String, Object> tgtsqlMap1 = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId1, //商品规格Id
															"istocknum",activityNum1,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap1, MapUtil.pojoToMap(ymtProductActivityStock1),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
			YmtProductActivityStock ymtProductActivityStock2=ymtProductActivityStockWapper.selectByCatalogId(catalogId2);
			Map<String, Object> tgtsqlMap2 = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId2, //商品规格Id
															"istocknum",activityNum2,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap2, MapUtil.pojoToMap(ymtProductActivityStock2),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			//check mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum1-activityNum1),productStockInfoWapper.getByCatalogId(catalogId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				Logger.verifyEquals((catalogNum2-activityNum2),productStockInfoWapper.getByCatalogId(catalogId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap1 = productActivityStockInfoWapper.getByCatalogIdId(catalogId1);
				Map<String, Object> tgtOldMongoMap1 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId1, //商品规格Id
																		"ActivityStockNum",(activityNum1),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongoMap1, productActivityStockInfoMap1,"Mongo-ProductActivityStockInfo ");
				
				
				Map<String, Object> productActivityStockInfoMap2 =  productActivityStockInfoWapper.getByCatalogIdId(catalogId2);
				Map<String, Object> tgtOldMongoMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId2, //商品规格Id
																		"ActivityStockNum",(activityNum2),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongoMap2, productActivityStockInfoMap2,"Mongo-ProductActivityStockInfo ");
				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean1 = new CatalogBean();
				CatalogBean.StockBean stockBean1_1 =catalogBean1.new StockBean();
				stockBean1_1.setStock(catalogNum1-activityNum1); 
				stockBean1_1.setStockType(0);
				
				CatalogBean.StockBean stockBean1_2 =catalogBean1.new StockBean();
				stockBean1_2.setStock(activityNum1);
				stockBean1_2.setProductInActivityId(productActivityId);
				stockBean1_2.setStockType(1);
				
				catalogBean1.setCatalogId(catalogId1);
				catalogBean1.setStockBean(Arrays.asList(stockBean1_1,stockBean1_2));
				
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean2_1 =catalogBean2.new StockBean();
				stockBean2_1.setStock(catalogNum2-activityNum2);
				stockBean2_1.setStockType(0);
				
				CatalogBean.StockBean stockBean2_2 =catalogBean2.new StockBean();
				stockBean2_2.setStock(activityNum2);
				stockBean2_2.setProductInActivityId(productActivityId);
				stockBean2_2.setStockType(1);
				
				catalogBean2.setCatalogId(catalogId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean2_1,stockBean2_2));
				
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean1,catalogBean2));
			}
			
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productActivityId);
			}
			
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_AuditProductActivityStock_003() {
		Logger.start(true, "初始化活动库存,原商品多规格,报名单规格");
		try{
			//发布商品 多规格
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc1.json");
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",sellerId,"LoginID",sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			
			
			YmtCatalogsI ymtCatalogsI1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId1 = ymtCatalogsI1.getsCatalogId();
			int catalogNum1 = ymtCatalogsI1.getiNum();
			String sku1 = ymtCatalogsI1.getsSKU();
			
			int activityNum1 = 10;
			
			
			YmtCatalogsI ymtCatalogsI2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1);
			String catalogId2 = ymtCatalogsI2.getsCatalogId();
			int catalogNum2 = ymtCatalogsI2.getiNum();
			
			List<String> catalogs = new ArrayList<>();
			catalogs.add(catalogId1);
			ActivityCallService.applyProductInActivity(sellerId, productId, String.valueOf(activityStartId), catalogs);
			int productActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			Logger.debug("ProductInActivityId: "+ productActivityId);
			
			//规格1 初始化库存
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("UserID", sellerId);
			updateMap.put("ActivityID", activityStartId);
			updateMap.put("ProductId", productId);
			updateMap.put("ProductActivityId", productActivityId);
			updateMap.put("IsFbxProduct", false);
			updateMap.put("FBXCatalogLockList[0]->CatalogId", catalogId1);
			updateMap.put("FBXCatalogLockList[0]->Stock", activityNum1);
			updateMap.put("FBXCatalogLockList[0]->Sku", sku1	);
			JSONObject retBean1 = activityStockCall.callAndGetReturnData(updateMap);
			
			Logger.verifyEquals(200, retBean1.getInt("Code"), "响应报文-返回码");
			Logger.verifyEquals(1, retBean1.getJSONObject("Data").getJSONObject("XLoboResult").getJSONArray("BatchLockResults").getJSONObject(0).getInt("Status"), "响应报文-返回码Status");
			
		

			//check sql
			//SQL-Ymt_Catalogs
			YmtCatalogsI ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId1);
			Logger.verifyEquals((catalogNum1-activityNum1), ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			YmtCatalogsI ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId2);
			Logger.verifyEquals((catalogNum2), ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			
			//SQL-Ymt_ProductActivityStock 商品库存数量
			YmtProductActivityStock ymtProductActivityStock1=ymtProductActivityStockWapper.selectByCatalogId(catalogId1);
			Map<String, Object> tgtsqlMap1 = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId1, //商品规格Id
															"istocknum",activityNum1,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap1, MapUtil.pojoToMap(ymtProductActivityStock1),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
	
			
			//check mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum1-activityNum1),productStockInfoWapper.getByCatalogId(catalogId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				Logger.verifyEquals((catalogNum2),productStockInfoWapper.getByCatalogId(catalogId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap1 = productActivityStockInfoWapper.getByCatalogIdId(catalogId1);
				Map<String, Object> tgtOldMongoMap1 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId1, //商品规格Id
																		"ActivityStockNum",(activityNum1),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongoMap1, productActivityStockInfoMap1,"Mongo-ProductActivityStockInfo ");
				
				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean1 = new CatalogBean();
				CatalogBean.StockBean stockBean1_1 =catalogBean1.new StockBean();
				stockBean1_1.setStock(catalogNum1-activityNum1); 
				stockBean1_1.setStockType(0);
				
				CatalogBean.StockBean stockBean1_2 =catalogBean1.new StockBean();
				stockBean1_2.setStock(activityNum1);
				stockBean1_2.setProductInActivityId(productActivityId);
				stockBean1_2.setStockType(1);
				
				catalogBean1.setCatalogId(catalogId1);
				catalogBean1.setStockBean(Arrays.asList(stockBean1_1,stockBean1_2));
				
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean2_1 =catalogBean2.new StockBean();
				stockBean2_1.setStock(catalogNum2);
				stockBean2_1.setStockType(0);
				
				catalogBean2.setCatalogId(catalogId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean2_1));
				
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean1,catalogBean2));
			}
			
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productActivityId);
			}
			
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_AuditProductActivityStock_004() {
		Logger.start(true, "初始化活动库存,原商品多规格,报名部分多规格");
		try{
			//发布商品 多规格
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc3.json");
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",sellerId,"LoginID",sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			YmtCatalogsI ymtCatalogsI1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId1 = ymtCatalogsI1.getsCatalogId();
			int catalogNum1 = ymtCatalogsI1.getiNum();
			String sku1 = ymtCatalogsI1.getsSKU();
			int activityNum1 = 10;
			
			
			YmtCatalogsI ymtCatalogsI2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1);
			String catalogId2 = ymtCatalogsI2.getsCatalogId();
			int catalogNum2 = ymtCatalogsI2.getiNum();
			String sku2 = ymtCatalogsI2.getsSKU();
			int activityNum2 = 11;
			
			YmtCatalogsI ymtCatalogsI3 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(2);
			String catalogId3 = ymtCatalogsI3.getsCatalogId();
			int catalogNum3= ymtCatalogsI3.getiNum();
			
			
			YmtCatalogsI ymtCatalogsI4 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(3);
			String catalogId4 = ymtCatalogsI4.getsCatalogId();
			int catalogNum4 = ymtCatalogsI4.getiNum();
			
			List<String> catalogs = new ArrayList<>();
			catalogs.add(catalogId1);
			catalogs.add(catalogId2);
			ActivityCallService.applyProductInActivity(sellerId, productId, String.valueOf(activityStartId), catalogs);
			int productActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			Logger.debug("ProductInActivityId: "+ productActivityId);
			
			
			//规格1 初始化库存
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("UserID", sellerId);
			updateMap.put("ActivityID", activityStartId);
			updateMap.put("ProductId", productId);
			updateMap.put("ProductActivityId", productActivityId);
			updateMap.put("IsFbxProduct", false);
			updateMap.put("FBXCatalogLockList[0]->CatalogId", catalogId1);
			updateMap.put("FBXCatalogLockList[0]->Stock", activityNum1);
			updateMap.put("FBXCatalogLockList[0]->Sku", sku1);
			updateMap.put("FBXCatalogLockList[1]->CatalogId", catalogId2);
			updateMap.put("FBXCatalogLockList[1]->Stock", activityNum2);
			updateMap.put("FBXCatalogLockList[1]->Sku", sku2);
			
			JSONObject retBean1 = activityStockCall.callAndGetReturnData("auditproductactivitystockcalltpl_001.json",updateMap);
			
			Logger.verifyEquals(200, retBean1.getInt("Code"), "响应报文-返回码");
			Logger.verifyEquals(1, retBean1.getJSONObject("Data").getJSONObject("XLoboResult").getJSONArray("BatchLockResults").getJSONObject(0).getInt("Status"), "响应报文-返回码Status");
			
		
		

			//check sql
			//SQL-Ymt_Catalogs
			YmtCatalogsI ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId1);
			Logger.verifyEquals((catalogNum1-activityNum1), ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			YmtCatalogsI ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId2);
			Logger.verifyEquals((catalogNum2-activityNum2), ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			YmtCatalogsI ymtCatalog3 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId3);
			Logger.verifyEquals((catalogNum3), ymtCatalog3.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			YmtCatalogsI ymtCatalog4 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId4);
			Logger.verifyEquals((catalogNum4), ymtCatalog4.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			
			//SQL-Ymt_ProductActivityStock 商品库存数量
			YmtProductActivityStock ymtProductActivityStock1=ymtProductActivityStockWapper.selectByCatalogId(catalogId1);
			Map<String, Object> tgtsqlMap1 = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId1, //商品规格Id
															"istocknum",activityNum1,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap1, MapUtil.pojoToMap(ymtProductActivityStock1),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			YmtProductActivityStock ymtProductActivityStock2=ymtProductActivityStockWapper.selectByCatalogId(catalogId2);
			Map<String, Object> tgtsqlMap2 = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId2, //商品规格Id
															"istocknum",activityNum2,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap2, MapUtil.pojoToMap(ymtProductActivityStock2),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
	
			
			//check mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum1-activityNum1),productStockInfoWapper.getByCatalogId(catalogId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				Logger.verifyEquals((catalogNum2-activityNum2),productStockInfoWapper.getByCatalogId(catalogId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				Logger.verifyEquals((catalogNum3),productStockInfoWapper.getByCatalogId(catalogId3).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				Logger.verifyEquals((catalogNum4),productStockInfoWapper.getByCatalogId(catalogId4).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap1 = productActivityStockInfoWapper.getByCatalogIdId(catalogId1);
				Map<String, Object> tgtOldMongoMap1 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId1, //商品规格Id
																		"ActivityStockNum",(activityNum1),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongoMap1, productActivityStockInfoMap1,"Mongo-ProductActivityStockInfo ");
				
				
				Map<String, Object> productActivityStockInfoMap2 = productActivityStockInfoWapper.getByCatalogIdId(catalogId2);
				Map<String, Object> tgtOldMongoMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId2, //商品规格Id
																		"ActivityStockNum",(activityNum2),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongoMap2, productActivityStockInfoMap2,"Mongo-ProductActivityStockInfo ");
				
				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean1 = new CatalogBean();
				CatalogBean.StockBean stockBean1_1 =catalogBean1.new StockBean();
				stockBean1_1.setStock(catalogNum1-activityNum1); 
				stockBean1_1.setStockType(0);
				CatalogBean.StockBean stockBean1_2 =catalogBean1.new StockBean();
				stockBean1_2.setStock(activityNum1);
				stockBean1_2.setProductInActivityId(productActivityId);
				stockBean1_2.setStockType(1);
				catalogBean1.setCatalogId(catalogId1);
				catalogBean1.setStockBean(Arrays.asList(stockBean1_1,stockBean1_2));
				
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean2_1 =catalogBean2.new StockBean();
				stockBean2_1.setStock(catalogNum2-activityNum2); 
				stockBean2_1.setStockType(0);
				CatalogBean.StockBean stockBean2_2 =catalogBean2.new StockBean();
				stockBean2_2.setStock(activityNum2);
				stockBean2_2.setProductInActivityId(productActivityId);
				stockBean2_2.setStockType(1);
				catalogBean2.setCatalogId(catalogId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean2_1,stockBean2_2));
				
				
				CatalogBean catalogBean3 = new CatalogBean();
				CatalogBean.StockBean stockBean3_1 =catalogBean3.new StockBean();
				stockBean3_1.setStock(catalogNum3);
				stockBean3_1.setStockType(0);
				catalogBean3.setCatalogId(catalogId3);
				catalogBean3.setStockBean(Arrays.asList(stockBean3_1));
				
				
				
				CatalogBean catalogBean4 = new CatalogBean();
				CatalogBean.StockBean stockBean4_1 =catalogBean4.new StockBean();
				stockBean4_1.setStock(catalogNum4);
				stockBean4_1.setStockType(0);
				catalogBean4.setCatalogId(catalogId4);
				catalogBean4.setStockBean(Arrays.asList(stockBean4_1));
				
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean1,catalogBean2,catalogBean3,catalogBean4));
			}
			
			
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productActivityId);
			}
			
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_AuditProductActivityStock_005() {
		Logger.start(true, "初始化活动库存,原商品超多规格,报名超多规格");
		try{
			int catalogAllNum = 400;
			List<Map<String, Object>> catalogInfoMapList = new ArrayList<Map<String, Object>>(); 
			
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc9.json");
			
			JSONArray CatalogListBean = addProductBean.getJSONObject("Product").getJSONArray("Catalogs");
			JSONObject CatalogFirst = CatalogListBean.getJSONObject(0);
			for(int i=1;i<catalogAllNum;i++){
				CatalogListBean.put(i, new JSONObject(CatalogFirst.toString()));
				
				CatalogListBean.getJSONObject(i).getJSONArray("PropertyValues").getJSONObject(1).getJSONArray("PropertyValues").getJSONObject(0).put("PropertyValue",String.valueOf(100+i));
			}
			
			
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",512003,"LoginID",sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			ActivityCallService.applyProductInActivity(sellerId, productId, String.valueOf(activityStartId), MapUtil.hashMap());
			
			int productActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			
			Logger.debug("ProductInActivityId: "+ productActivityId);
			int activityNum = 10;
			
			
			
			//初始化库存
			JSONObject auditStockBean = JsonBeanHelper.getJsonBean("com.ymatou.productstock.api/AuditProductActivityStockCall/auditproductactivitystockcalltpl.json");
			JSONArray FBXCatalogLockListBean = auditStockBean.getJSONArray("FBXCatalogLockList");
			JSONObject CatalogFirstBean = FBXCatalogLockListBean.getJSONObject(0);
			
			
			
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("UserID", sellerId);
			updateMap.put("ActivityID", activityStartId);
			updateMap.put("ProductId", productId);
			updateMap.put("ProductActivityId", productActivityId);
			updateMap.put("IsFbxProduct", false);
			JsonBeanHelper.updateJsonBean(auditStockBean, updateMap);
			
			
			
			List<YmtCatalogsI> YmtCatalogsList = ymtCatalogsIWapper.selectCatalogsByProductId(productId);
			for(int i=0;i<YmtCatalogsList.size();i++){
				String catalogId = YmtCatalogsList.get(i).getsCatalogId();
				int catalogNum = YmtCatalogsList.get(i).getiNum();
				String sku = YmtCatalogsList.get(i).getsSKU();
				
				
				Map<String, Object> map = MapUtil.hashMap("catalogId", catalogId, "catalogNum", catalogNum, "sku", sku);
				catalogInfoMapList.add(map);
				
				
				FBXCatalogLockListBean.put(i, new JSONObject(CatalogFirstBean.toString()));
				
				FBXCatalogLockListBean.getJSONObject(i).put("CatalogId", catalogId);
				FBXCatalogLockListBean.getJSONObject(i).put("Sku", sku);
				FBXCatalogLockListBean.getJSONObject(i).put("Stock", activityNum);
			}
			JSONObject retBean = activityStockCall.callAndGetReturnData(auditStockBean);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				YMTDateUtil.waitTime(10);
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productActivityId);
			}
			
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	
	}
	
	
}
